package com.example.shopp_2301.adapter

import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.Order
import com.example.base.entity.OrderInfo
import com.example.shopp_2301.R
import com.example.shopp_2301.utils.GlideUtils

class OrderAdapter:BaseQuickAdapter<Order,BaseViewHolder>(R.layout.item_order) {
    override fun convert(holder: BaseViewHolder, item: Order) {
        holder.setText(R.id.order_time,item.createTime)
        holder.setText(R.id.order_status,item.orderStatus)
        holder.setText(R.id.order_total,"共${item.totalNum}件商品，合计金额￥${item.payPrice}")
        if(item.orderStatus=="待支付"){
            holder.getView<TextView>(R.id.pay_now).text = "立即付款"
        }else{
            holder.getView<TextView>(R.id.pay_now).text = "查看详情"
        }
        val recyclerView1 = holder.getView<RecyclerView>(R.id.order_rv)
        val orderChildAdapter = OrderChildAdapter()
        orderChildAdapter.data.addAll(item.orderInfoList)
        recyclerView1.adapter = orderChildAdapter
        recyclerView1.layoutManager = LinearLayoutManager(context)
    }
}

class OrderChildAdapter:BaseQuickAdapter<OrderInfo,BaseViewHolder>(R.layout.item_order_child){
    override fun convert(holder: BaseViewHolder, item: OrderInfo) {
        GlideUtils.loadImage(context,item.image,holder.getView(R.id.pre_image))
        holder.setText(R.id.pre_name,item.storeName)
        holder.setText(R.id.pre_price,item.price)
        holder.setText(R.id.pre_num,"X ${item.cartNum}")
    }

}